package StudyCode.summary.myfile;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.Calendar;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class SettingFileTimeRelatedAttributes {
	public static void main(String[] args) throws Exception {
		Path path = Paths.get("E:\\迅雷下载\\test1.txt");
		BasicFileAttributeView view = Files.getFileAttributeView(path,
				BasicFileAttributeView.class);
		FileTime lastModifiedTime;
		FileTime lastAccessTime;
		FileTime createTime;

		BasicFileAttributes attributes = view.readAttributes();
		lastModifiedTime = attributes.lastModifiedTime();
		createTime = attributes.creationTime();

		long currentTime = Calendar.getInstance().getTimeInMillis();
		lastAccessTime = FileTime.fromMillis(currentTime);
		view.setTimes(lastModifiedTime, lastAccessTime, createTime);

		System.out.println("最后修改时间:" + lastModifiedTime.toString());
		System.out.println("最后访问时间:" + attributes.lastAccessTime());
		System.out.println("创建时间:" + createTime.toString());
	}
}
